package com.x.erp.manage;

import com.x.erp.dao.CarAgeDao;
import com.x.erp.model.CarAge;
import com.x.framework.manage.BaseManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 车龄信息Mapper
 */
@Service
public class CarAgeManage extends BaseManage {

	@Autowired
	private CarAgeDao carAgeDao;// 车龄信息DAO

	/**
	 * 修改车龄信息任务
	 * @param carAge
	 * @return
	 * @throws Exception 
	 */
	public int updateCarAgeTask(CarAge carAge) throws Exception {
		List<CarAge> carAges = carAgeDao.selectCarAgeList(carAge);
		int i = 0;
		if(carAges != null) {
			for(CarAge age : carAges) {
				if(!this.getDate(age.getCarAgeFrom(), "yyyy-MM-dd").equals("1900-01-01")) {
					age.setCarAgeFrom(this.getDate(age.getCarAgeFrom(), 1));
				}
				age.setCarAgeTo(this.getDate(age.getCarAgeTo(), 1));
				i += this.update(age);
			}
		}
		return i;
	}

}
